package com.example.springboot_springsecurity_jwt_redis.securityHandler;

import com.alibaba.fastjson.JSON;
import com.example.springboot_springsecurity_jwt_redis.common.Result;
import com.example.springboot_springsecurity_jwt_redis.common.ResultCodeEnum;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 无权访问
 */
@Component
public class AjaxAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, org.springframework.security.access.AccessDeniedException e) throws IOException, ServletException {
        httpServletResponse.getWriter().write(JSON.toJSONString(Result.result(ResultCodeEnum.RESULT_CODE_USER_NO_ACCESS,false)));
    }
}
